﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;

namespace OpenXmlSdkSample
{
    public static class DataCreator
    {
        public static ExcelExportModel GetModel(List<StudentScore> list)
        {
            ExcelExportModel model = new ExcelExportModel();
            DataTable dt = GetDataTable(list);
            model.Data = dt;
            model.Headers = GetHeaders(dt);


            return model;
        }

        private static List<string> GetHeaders(DataTable dt)
        {
            List<string> list = new List<string>();
            foreach (DataColumn col in dt.Columns)
            {
                list.Add(col.ColumnName);
            }

            return list;
        }


        public static DataTable GetDataTable(List<StudentScore> list)
        {
            DataTable dt = new DataTable();

            Type type = typeof(StudentScore);
            PropertyInfo[] props = type.GetProperties();
            foreach (PropertyInfo prop in props)
            {
                dt.Columns.Add(new DataColumn()
                {
                    DataType = prop.PropertyType,
                    ColumnName = prop.Name
                });
            }

            foreach (StudentScore item in list)
            {
                DataRow row = dt.NewRow();
                row["Adjust"] = item.Adjust;
                row["Area"] = item.Area;
                row["Bed"] = item.Bed;
                row["Charge"] = item.Charge;
                row["Company"] = item.Company;
                row["CustomerName"] = item.CustomerName;
                row["Hours"] = item.Hours;
                row["Note"] = item.Note;
                row["ServiceProject"] = item.ServiceProject;
                row["ServiceTime"] = item.ServiceTime;
                row["ServiceType"] = item.ServiceType;
                row["Shift"] = item.Shift;
                row["UserName"] = item.UserName;
                row["UserType"] = item.UserType;
                dt.Rows.Add(row);
            }

            return dt;
        }


        public static List<StudentScore> GetSingleHeaderSingleRow()
        {
            List<StudentScore> list = new List<StudentScore>();
            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "C08",
                Bed = "815",
                Charge = 56,
                Company = "复医",
                CustomerName = "裴英",
                Hours = 24,
                Note = "哈哈",
                ServiceProject = "病人护理一对多-80",
                ServiceTime = DateTime.Now.AddDays(-68).ToString("yyyy-MM-dd"),
                ServiceType = "护工",
                Shift = "全班",
                UserName = "张三",
                UserType = "外包"
            });
            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "C07",
                Bed = "8-715",
                Charge = 56,
                Company = "复医",
                CustomerName = "宋祖德",
                Hours = 24,
                Note = "歼击机",
                ServiceProject = "病人护理一对多-80",
                ServiceTime = DateTime.Now.AddDays(-100).ToString("yyyy-MM-dd"),
                ServiceType = "护工",
                Shift = "夜班",
                UserName = "李四",
                UserType = "合同"
            });
            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "C18",
                Bed = "112",
                Charge = 56,
                Company = "复医",
                CustomerName = "陆美芝",
                Hours = 24,
                Note = "测试",
                ServiceProject = "病人护理一对多-80",
                ServiceTime = DateTime.Now.AddDays(-88).ToString("yyyy-MM-dd"),
                ServiceType = "护工",
                Shift = "白班",
                UserName = "王五",
                UserType = "编制"
            });

            return list;
        }

        public static List<StudentScore> GetSingleHeaderMergeRow()
        {
            List<StudentScore> list = new List<StudentScore>();
            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "C07",
                Bed = "BB",
                Charge = 56,
                Company = "复医",
                CustomerName = "裴英",
                Hours = 24,
                Note = "哈哈",
                ServiceProject = "病人护理一对多-80",
                ServiceTime = DateTime.Now.AddDays(-68).ToString("yyyy-MM-dd"),
                ServiceType = "护工",
                Shift = "全班",
                UserName = "张三",
                UserType = "外包"
            });
            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "C08",
                Bed = "AA",
                Charge = 56,
                Company = "复医",
                CustomerName = "裴英",
                Hours = 24,
                Note = "哈哈",
                ServiceProject = "病人护理一对多-80",
                ServiceTime = DateTime.Now.AddDays(-68).ToString("yyyy-MM-dd"),
                ServiceType = "护工",
                Shift = "全班",
                UserName = "张三",
                UserType = "外包"
            });
            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "C09",
                Bed = "ABC",
                Charge = 56,
                Company = "复医",
                CustomerName = "裴英",
                Hours = 24,
                Note = "哈哈",
                ServiceProject = "病人护理一对多-80",
                ServiceTime = DateTime.Now.AddDays(-68).ToString("yyyy-MM-dd"),
                ServiceType = "护工",
                Shift = "全班",
                UserName = "张三",
                UserType = "外包"
            });
            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "",
                Bed = "",
                Charge = 168,
                Company = "",
                CustomerName = "",
                Hours = 72,
                Note = "",
                ServiceProject = "",
                ServiceTime = "小计",
                ServiceType = "",
                Shift = "",
                UserName = "张三",
                UserType = "外包"
            });



            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "CB07",
                Bed = "B715",
                Charge = 56,
                Company = "复医",
                CustomerName = "宋祖德",
                Hours = 24,
                Note = "歼击机",
                ServiceProject = "病人护理一对多-80",
                ServiceTime = DateTime.Now.AddDays(-100).ToString("yyyy-MM-dd"),
                ServiceType = "护工",
                Shift = "夜班",
                UserName = "李四",
                UserType = "合同"
            });
            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "CA07",
                Bed = "A715",
                Charge = 56,
                Company = "复医",
                CustomerName = "宋祖德",
                Hours = 24,
                Note = "歼击机",
                ServiceProject = "病人护理一对多-80",
                ServiceTime = DateTime.Now.AddDays(-100).ToString("yyyy-MM-dd"),
                ServiceType = "护工",
                Shift = "夜班",
                UserName = "李四",
                UserType = "合同"
            });
            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "",
                Bed = "",
                Charge = 168,
                Company = "",
                CustomerName = "",
                Hours = 72,
                Note = "",
                ServiceProject = "",
                ServiceTime = "小计",
                ServiceType = "",
                Shift = "",
                UserName = "李四",
                UserType = "合同"
            });



            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "C18",
                Bed = "112",
                Charge = 56,
                Company = "复医",
                CustomerName = "陆美芝",
                Hours = 24,
                Note = "测试",
                ServiceProject = "病人护理一对多-80",
                ServiceTime = DateTime.Now.AddDays(-88).ToString("yyyy-MM-dd"),
                ServiceType = "护工",
                Shift = "白班",
                UserName = "王五",
                UserType = "编制"
            });
            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "",
                Bed = "",
                Charge = 168,
                Company = "",
                CustomerName = "",
                Hours = 72,
                Note = "",
                ServiceProject = "",
                ServiceTime = "小计",
                ServiceType = "",
                Shift = "",
                UserName = "王五",
                UserType = "编制"
            });

            return list;
        }

        public static List<StudentScore> GetSingleHeaderMergeRow1()
        {
            List<StudentScore> list = new List<StudentScore>();
            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "C07",
                Bed = "BB",
                Charge = 56,
                Company = "复医",
                CustomerName = "裴英",
                Hours = 24,
                Note = "哈哈",
                ServiceProject = "病人护理一对多-80",
                ServiceTime = DateTime.Now.AddDays(-68).ToString("yyyy-MM-dd"),
                ServiceType = "护工",
                Shift = "全班",
                UserName = "张三",
                UserType = "外包"
            });
            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "C08",
                Bed = "AA",
                Charge = 56,
                Company = "复医",
                CustomerName = "裴英",
                Hours = 24,
                Note = "哈哈",
                ServiceProject = "病人护理一对多-80",
                ServiceTime = "",
                ServiceType = "护工",
                Shift = "全班",
                UserName = "",
                UserType = ""
            });
            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "C09",
                Bed = "ABC",
                Charge = 56,
                Company = "复医",
                CustomerName = "裴英",
                Hours = 24,
                Note = "哈哈",
                ServiceProject = "病人护理一对多-80",
                ServiceTime = "",
                ServiceType = "护工",
                Shift = "全班",
                UserName = "",
                UserType = ""
            });
            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "",
                Bed = "",
                Charge = 168,
                Company = "",
                CustomerName = "",
                Hours = 72,
                Note = "",
                ServiceProject = "",
                ServiceTime = "小计",
                ServiceType = "",
                Shift = "",
                UserName = "",
                UserType = ""
            });



            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "CB07",
                Bed = "B715",
                Charge = 56,
                Company = "复医",
                CustomerName = "宋祖德",
                Hours = 24,
                Note = "歼击机",
                ServiceProject = "病人护理一对多-80",
                ServiceTime = DateTime.Now.AddDays(-100).ToString("yyyy-MM-dd"),
                ServiceType = "护工",
                Shift = "夜班",
                UserName = "李四",
                UserType = "合同"
            });
            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "CA07",
                Bed = "A715",
                Charge = 56,
                Company = "复医",
                CustomerName = "宋祖德",
                Hours = 24,
                Note = "歼击机",
                ServiceProject = "病人护理一对多-80",
                ServiceTime = "",
                ServiceType = "护工",
                Shift = "夜班",
                UserName = "",
                UserType = ""
            });
            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "",
                Bed = "",
                Charge = 168,
                Company = "",
                CustomerName = "",
                Hours = 72,
                Note = "",
                ServiceProject = "",
                ServiceTime = "小计",
                ServiceType = "",
                Shift = "",
                UserName = "",
                UserType = ""
            });



            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "C18",
                Bed = "112",
                Charge = 56,
                Company = "复医",
                CustomerName = "陆美芝",
                Hours = 24,
                Note = "测试",
                ServiceProject = "病人护理一对多-80",
                ServiceTime = DateTime.Now.AddDays(-88).ToString("yyyy-MM-dd"),
                ServiceType = "护工",
                Shift = "白班",
                UserName = "王五",
                UserType = "编制"
            });
            list.Add(new StudentScore()
            {
                Adjust = 0,
                Area = "",
                Bed = "",
                Charge = 168,
                Company = "",
                CustomerName = "",
                Hours = 72,
                Note = "",
                ServiceProject = "",
                ServiceTime = "小计",
                ServiceType = "",
                Shift = "",
                UserName = "",
                UserType = ""
            });

            return list;
        }
    }
}

